package com.changan.model;

import com.beust.jcommander.Parameter;
import lombok.Getter;
import lombok.Setter;
import org.apache.flink.runtime.externalresource.StaticExternalResourceInfoProvider;

import javax.xml.soap.SAAJResult;
import java.io.Serializable;

/**
 * @author roohom
 */
@Setter
@Getter
public class AppArgs implements Serializable {
    /**
     * 任务名
     */
    @Parameter(names = {"-jn", "--job-name"}, required = true, description = "specify the job name of a flink job.")
    private String jobName;

    @Parameter(names = {"-sn", "--source-name"}, required = false, description = "a source name.")
    private String sourceName;

    @Parameter(names = {"-st", "--source-table"}, required = true, description = "comma-separated list of source table names you want to sync.")
    private String sourceTableName;

    @Parameter(names = {"-spk", "--source-primary-keys"}, required = true, description = "semicolon-separated list of source table primary key columns.")
    private String sourcePk;

    @Parameter(names = {"-tn", "--target-name"}, required = false, description = "a target name.")
    private String targetName;

    @Parameter(names = {"-si", "--server-id"}, required = false, description = "database server id")
    private String serverId = "6400-7800";

    @Parameter(names = {"-tt", "--target-table-name"}, required = true, description = "comma-separated list of target table name.")
    private String targetTableName;

    @Parameter(names = {"-tpk", "--target-primary-keys"}, required = true, description = "semicolon-separated list of target table primary key columns.")
    private String targetPk;

    @Parameter(names = {"-kf", "--kafka"}, required = false, description = "kafka实例名")
    private String kafka;

    @Parameter(names = {"-kt", "--kafka-topics"}, required = true, description = "comma-separated list of kafka topics.")
    private String kafkaTopic;

    @Parameter(names = {"-ka", "--kafka-address"}, required = true, description = "comma-separated list of kafka address.")
    private String kafkaAddress;

    @Parameter(names = {"-kp", "--kafka-pk"}, required = false, description = "semicolon-separated list of kafka topic primary key columns.")
    private String kafkaPk;

    @Parameter(names = {"-kts", "--kafka-topic-suffix"}, required = false, description = "kafka的topic后缀")
    private String kafkaTopicSuffix;

    @Parameter(names = {"-kgp", "--kafka-group-id"}, required = false, description = "kafka消费者组id")
    private String kafkaGroupId;

    @Parameter(names = {"-kssm", "--kafka-scan-mode"}, required = false, description = "启动时kafka消费策略，earliest-offset/latest-offset/group-offsets/timestamp")
    private String scanStartUpMode;

    @Parameter(names = {"-ksst", "--kafka-scan-timestamp"}, required = false, description = "启动时kafka消费策略，当指定消费策略为timestamp时有效, 传入的值为一个milliseconds")
    private String scanStartUpTimestamp;

    @Parameter(names = {"-sa", "--source-address"}, required = true, description = "源数据库的地址(JDBC URL)")
    private String sourceAddress;

    @Parameter(names = {"-un", "--user-name"}, required = true, description = "源数据库用户名")
    private String userName;

    @Parameter(names = {"-pw", "--password"}, required = true, description = "源数据库密码")
    private String password;

    @Parameter(names = {"-hs", "--host"}, required = true, description = "源数据库HOST")
    private String host;

    @Parameter(names = {"-pt", "--port"}, required = true, description = "源数据库PORT")
    private String port;

    @Parameter(names = {"-db", "--database"}, required = true, description = "源数据库库名")
    private String databaseName;

    @Parameter(names = {"-ta", "--target-address"}, required = true, description = "Starrocks的jdbc-url和load-url,以|分隔，如: jdbc-url=jdbc:mysql://192.168.1.1:9030|load-url=192.168.1.1:8030")
    private String targetAddress;

    @Parameter(names = {"-tu", "--target-user-name"}, required = true, description = "Starrocks的用户名")
    private String targetUserName;

    @Parameter(names = {"-tpw", "--target-password"}, required = true, description = "Starrocks的密码")
    private String targetPassword;

    @Parameter(names = {"-tdb", "--target-database"}, required = true, description = "Starrocks数据库库名")
    private String targetDatabase;

    @Parameter(names = {"-sum", "--startup-mode"}, required = false, description = "启动模式, initial/earliest/latest")
    private String startUpMode;

    @Override
    public String toString() {
        return "AppArgs: [" +
                "-jn " + jobName +
                " -sn " + sourceName +
                " -st " + sourceTableName +
                " -spk " + sourcePk +
                " -tn " + targetName +
                " -tt " + targetTableName +
                " -tpk " + targetPk +
                " -kf " + kafka +
                " -kt " + kafkaTopic +
                " -ka " + kafkaAddress +
                " -kp " + kafkaPk +
                " -kts " + kafkaTopicSuffix +
                " -kgp " + kafkaGroupId +
                " -kssm " + scanStartUpMode +
                " -ksst " + scanStartUpTimestamp +
                " -sa " + sourceAddress +
                " -un " + userName +
                " -pw " + password +
                " -hs " + host +
                " -pt " + port +
                " -db " + databaseName +
                " -ta " + targetAddress +
                " -tu " + targetUserName +
                " -tpw " + targetPassword +
                " -tdb " + targetDatabase +
                " -sum " + startUpMode +
                " -h " + help +
                ']';
    }

    /**
     * 显示帮助信息
     */
    @Parameter(names = {"-h", "--help"}, help = true)
    private Boolean help;

}
